package leetcode;

/**
 * @author MaoLin Wang
 * @date 2020/10/8 3:57 下午
 */
public class _31下一个排列 {
    public static void nextPermutation(int[] nums) {
      int i=nums.length-2;
      int j=nums.length-1;
      int k=nums.length-1;

      while (i>=0 && nums[i]>=nums[j]){
          i--;j--;
      }
      if (i>=0){
          while (k>=0 && nums[k]<nums[i]){
              k--;
          }
          swap(nums,i,k);
      }
      int left=i+1;
      int right=nums.length-1;
      while (left<right){
          swap(nums,left,right);
          left++;
          right--;
      }
    }
    public static void swap(int[] nums,int i,int k){
        int temp=nums[i];
        nums[i]=nums[k];
        nums[k]=temp;
    }

    public static void main(String[] args) {
        int[]ints=new int[]{1,1};
        nextPermutation(ints);
        for (int anInt : ints) {
            System.out.println(anInt);
        }
    }
}
